<?php
$q=$_GET["q"];
$array= explode(",",$q);
$s_type=$array[0];
$School_Id=$array[1];
$Access_Type=$array[2];
$Id=$Access_Type.",".$School_Id.",School_Id";
$hint="";
include_once '../Login/databaseconnection.php';
if($s_type!=""&&$School_Id!="")
{
if($s_type=="Academic staff")
{
$get_gra_tea=mysql_query("SELECT COUNT(T_NIC_Number) AS No_Gra FROM teacher WHERE Academic_Qualifications LIKE '%deg_%' AND School_Id='$School_Id'");
if($get_gra_tea)
{
if($row_gra=mysql_fetch_array($get_gra_tea))
{
$Graduate_Teachers=$row_gra['No_Gra'];
}
else
{
$Graduate_Teachers='0';
}
}

$all_tea=mysql_query("SELECT * FROM teacher WHERE School_Id='$School_Id'");
if($all_tea)
{
while($rowalltea=mysql_fetch_array($all_tea))
{
if(empty($All_Teachers))
{
$All_Teachers='"'.$rowalltea['T_NIC_Number'].'"';
}
else
{
$All_Teachers=$All_Teachers.',"'.$rowalltea['T_NIC_Number'].'"';
}
}
}
if($All_Teachers!="")
{
$get_res_per=mysql_query("SELECT COUNT(DISTINCT(T_NIC_Number)) AS No_Res_Per FROM resource_team GROUP BY T_NIC_Number HAVING T_NIC_Number in ($All_Teachers)");
if($get_res_per)
{
if($row_res_per=mysql_fetch_array($get_res_per))
{
$Res_Persons=$row_res_per['No_Res_Per'];
}
else
{
$Res_Persons='0';
}
}
}
$tot_f_tea=mysql_query("SELECT COUNT(T_NIC_Number) AS tot_f_teachers FROM teacher WHERE (Gender='Female' OR Gender='female') AND School_Id='$School_Id'");
if($tot_f_tea)
{
if($row_fe_tea=mysql_fetch_array($tot_f_tea))
{
$Female_Teachers=$row_fe_tea['tot_f_teachers'];
}
else
{
$Female_Teachers='0';
}
}
$tot_m_tea=mysql_query("SELECT COUNT(T_NIC_Number) AS tot_f_teachers FROM teacher WHERE (Gender='Male' OR Gender='male') AND School_Id='$School_Id'");
if($tot_m_tea)
{
if($row_ma_tea=mysql_fetch_array($tot_m_tea))
{
$Male_Teachers=$row_ma_tea['tot_f_teachers'];
}
else
{
$Male_Teachers='0';
}
}
if(($Male_Teachers==""&&$Female_Teachers=="")||($Male_Teachers=="0"&&$Female_Teachers=="0"))
	{
	$hint=$hint.'<font color="red">There are no staff details for this school</font><br/>';
	}
$hint=$hint.'<table height="175" class="imgholder"> 
      <tr>
        <th>        
        </th>
         <td>
        </td>
         </tr> 
      <tr>
        <th>        
         <label>Number of male teachers:</label>
         </th>
         <td>';
if($Male_Teachers!="0")
{
$hint=$hint."<input type='text' name='Male_Teachers' value='$Male_Teachers' readonly='readonly' id='$Id' onmouseover='getdetails_popup(this.name,this.id)'/>";
}
else
{
$hint=$hint."<input type='text' name='Male_Teachers' value='$Male_Teachers' readonly='readonly' onmouseover='clearpopbox()'/>";
}
$hint=$hint.'</td>
         </tr>   
       <tr>
        <th>        
         <label>Number of female teachers:</label>
         </th>
         <td>';
if($Female_Teachers!="0")
{
$hint=$hint."<input type='text' name='Female_Teachers' value='$Female_Teachers' readonly='readonly' id='$Id' onmouseover='getdetails_popup(this.name,this.id)'/>";
}
else
{
$hint=$hint."<input type='text' name='Female_Teachers' value='$Female_Teachers' readonly='readonly' onmouseover='clearpopbox()'/>";
}
$hint=$hint.'</td>
         </tr>         
         <tr>
        <th>        
         <label>Number of resource persons:</label>
         </th>
         <td>';
if($Res_Persons!="0")
{
$hint=$hint."<input type='text' name='Res_Persons' value='$Res_Persons' readonly='readonly' id='$Id' onmouseover='getdetails_popup(this.name,this.id)'/>";
}
else
{
$hint=$hint."<input type='text' name='Res_Persons' value='$Res_Persons' readonly='readonly' onmouseover='clearpopbox()'/>";
}
$hint=$hint.'</td>
         </tr>
         <tr>
        <th>        
         <label>Number of graduate teachers:</label>
         </th>
         <td>';
if($Graduate_Teachers!="0")
{
$hint=$hint."<input type='text' name='Graduate_Teachers' value='$Graduate_Teachers' readonly='readonly' id='$Id' onmouseover='getdetails_popup(this.name,this.id)'/>";
}
else
{
$hint=$hint."<input type='text' name='Graduate_Teachers' value='$Graduate_Teachers' readonly='readonly' onmouseover='clearpopbox()'/>";
}
$hint=$hint.'</td>
         </tr>
         <tr>
        <th><form name="a_s">
         <label>Number of </label>';
		 $hint=$hint."<select name='Appo_Sub' id='$School_Id' onChange='showAppTea(this.value,this.id)' onmouseover='clearpopbox()'>";
	  $app_s=mysql_query("SELECT DISTINCT(Appointed_Subject) FROM teacher WHERE  School_Id='$School_Id'");
 while($rowapp_s=mysql_fetch_array($app_s))
  {
  if(empty($sub))
  {
  $sub=$rowapp_s['Appointed_Subject'];
  }
	 $Appointed_Subject=$rowapp_s['Appointed_Subject'];
	$hint=$hint.'<option value="'.$Appointed_Subject.'">'.$Appointed_Subject.'</option>';
  }
$hint=$hint.'</select><label> Teachers:</label>
         </form></th>
         <td>';
		 	 $tot_tea=mysql_query("SELECT COUNT(T_NIC_Number) AS tot_teachers FROM teacher WHERE Appointed_Subject='$sub' AND School_Id='$School_Id'");
if($tot_tea)
{
if($row_tea=mysql_fetch_array($tot_tea))
{
$App_Teachers=$row_tea['tot_teachers'];
}
}
$hint=$hint."<div id='Appo_Tea'>";
if($App_Teachers!="0")
{
$hint=$hint."<input type='text' name='No_Appo_Teachers' value='$App_Teachers' readonly='readonly' id='$Id' onmouseover='getdetails_popup(this.name,this.id)'/>";
}
else
{
$hint=$hint."<input type='text' name='No_Appo_Teachers' value='$App_Teachers' readonly='readonly' onmouseover='clearpopbox()'/>";
}
$hint=$hint."</div>";
$hint=$hint.'</td>
         </tr>
  </table>';
  }
  if($s_type=="Non academic staff")
{
$N_A_Staff=mysql_query("SELECT SUM(No_Of_Permanent_Staffs) AS P_S,SUM(No_Of_Casual_Staffs) AS C_S FROM non_acadamic_staff WHERE School_Id='$School_Id'");
if($N_A_Staff)
{
if($rowN_A_Staff=mysql_fetch_array($N_A_Staff))
{
$Tot_N_A_P_Staff=$rowN_A_Staff['P_S'];
$Tot_N_A_C_Staff=$rowN_A_Staff['C_S'];
$Tot_N_A_Staff=$Tot_N_A_C_Staff+$Tot_N_A_P_Staff;
}
}
$hint=$hint.'<label>Total number of N.A.Staff:</label>';
$hint=$hint."<input type='text' name='Tot_N_A_Staff' value='$Tot_N_A_Staff' readonly='readonly' onmouseover='clearpopbox()'/>";
$hint=$hint.'<br/>
<br/><label>Designation:</label><form name="desig">';
		 $hint=$hint."<select name='Designation' id='$School_Id' onChange='Designation(this.value,this.id)' onmouseover='clearpopbox()'>";
	  $desi=mysql_query("SELECT DISTINCT(Designation) FROM non_acadamic_staff WHERE School_Id='$School_Id'");
 $desig="";
 while($rowdesi=mysql_fetch_array($desi))
  {
  if(empty($desig))
  {
  $desig=$rowdesi['Designation'];
  }
	$hint=$hint.'<option value="'.$rowdesi['Designation'].'">'.$rowdesi['Designation'].'</option>';
  }
$n_a_c=mysql_query("SELECT * FROM non_acadamic_staff WHERE Designation='$desig' AND School_Id='$School_Id'");
if($n_a_c)
{
if($rown_a_c=mysql_fetch_array($n_a_c))
{
$No_Of_Required_Staffs=$rown_a_c['No_Of_Required_Staffs'];
$No_Of_Approved_Staffs=$rown_a_c['No_Of_Approved_Staffs'];
$No_Of_Permanent_Staffs=$rown_a_c['No_Of_Permanent_Staffs'];
$No_Of_Casual_Staffs=$rown_a_c['No_Of_Casual_Staffs'];
$Relief=$rown_a_c['Relief'];
$Tot_Staff=$No_Of_Permanent_Staffs+$No_Of_Casual_Staffs;
}
else
{
$No_Of_Required_Staffs='0';
$No_Of_Approved_Staffs='0';
$No_Of_Permanent_Staffs='0';
$No_Of_Casual_Staffs='0';
$Relief='_';
$Tot_Staff='0';
}
}
$hint=$hint.'</select></form><div id="Designation">
<table height="175" class="imgholder"> 
         <tr>
        <th><label>Number of '.$desig.'s:</label></th>
         <td>';
$hint=$hint."<input type='text' name='Tot_Staff' value='$Tot_Staff' readonly='readonly' onmouseover='clearpopbox()'/>";
$hint=$hint.'</td>
         </tr>   
       <tr>
        <th>        
         <label>Number of Required Staffs:</label>
         </th>
         <td>';
         $hint=$hint."<input type='text' name='No_Of_Required_Staffs' value='$No_Of_Required_Staffs' readonly='readonly' onmouseover='clearpopbox()'/>";
$hint=$hint.'</td>
         </tr>         
         <tr>
        <th>        
         <label>Number of Approved Staffs:</label>
         </th>
         <td>';
        $hint=$hint."<input type='text' name='No_Of_Approved_Staffs' value='$No_Of_Approved_Staffs' readonly='readonly' onmouseover='clearpopbox()'/>";
$hint=$hint.'</td>
         </tr>
         <tr>
        <th>        
         <label>Number of Permanent Staffs:</label>
         </th>
         <td>';
$hint=$hint."<input type='text' name='No_Of_Permanent_Staffs' value='$No_Of_Permanent_Staffs' readonly='readonly' onmouseover='clearpopbox()'/>";
$hint=$hint.'</td>
         </tr>
		 <tr>
        <th>        
         <label>Number of Casual Staffs:</label>
         </th>
         <td>';
$hint=$hint."<input type='text' name='No_Of_Casual_Staffs' value='$No_Of_Casual_Staffs' readonly='readonly' onmouseover='clearpopbox()'/>";
$hint=$hint.'</td>
         </tr>   
       <tr>
	   <tr>
        <th>        
         <label>Relief:</label>
         </th>
         <td>';
$hint=$hint."<input type='text' name='Relief' value='$Relief' readonly='readonly' onmouseover='clearpopbox()'/>";
$hint=$hint.'</td>
         </tr>   
       <tr></table></div>';
}
  }
  if($hint=="")
{
if($School_Id=="")
{
$response="<font color='red'>*Please select a school!</font>";
}
if($s_type=="Academic staff")
{
$response=$response.'<table height="175" class="imgholder"> 
      <tr>
        <th>        
        </th>
         <td>
        </td>
         </tr> 
      <tr>
        <th>        
         <label>Number of male teachers:</label>
         </th>
         <td>';
         $response=$response."<input type='text' name='Male_Teachers' value='$Male_Teachers' readonly='readonly'/>";
$response=$response.'</td>
         </tr>   
       <tr>
        <th>        
         <label>Number of female teachers:</label>
         </th>
         <td>';
         $response=$response."<input type='text' name='Female_Teachers' value='$Female_Teachers' readonly='readonly'/>";
$response=$response.'</td>
         </tr>         
         <tr>
        <th>        
         <label>Number of resource persons:</label>
         </th>
         <td>';
        $response=$response."<input type='text' name='Res_Persons' value='$Res_Persons' readonly='readonly'/>";
$response=$response.'</td>
         </tr>
         <tr>
        <th>        
         <label>Number of graduate teachers:</label>
         </th>
         <td>';
         $response=$response."<input type='text' name='Graduate_Teachers' value='$Graduate_Teachers' readonly='readonly'/>";
$response=$response.'</td>
         </tr>
         <tr>
        <th>        
         <label>Number of </label>';
		 $response=$response."<select name='Appo_Sub' id='$School_Id' onChange='showAppTea(this.value,this.id)'>";
        	$response=$response.'<option value="Select One">Select One</option>';
	  $app_s=mysql_query("SELECT DISTINCT(Appointed_Subject) FROM teacher WHERE  School_Id='$School_Id'");
 while($rowapp_s=mysql_fetch_array($app_s))
  {
	 $Appointed_Subject=$rowapp_s['Appointed_Subject'];
	$response=$response.'<option value="'.$Appointed_Subject.'">'.$Appointed_Subject.'</option>';
  }
$response=$response.'</select><label> Teachers:</label>
         </th>
         <td>';
        $response=$response."<div id='Appo_Tea'><input type='text' name='No_Appo_Teachers' readonly='readonly'/></div>";
$response=$response.'</td>
         </tr>
  </table>';
  }
  if($s_type=="Non academic staff")
{
$response=$response.'<table height="175" class="imgholder"> 
      <tr>
        <th>        
        </th>
         <td>
        </td>
         </tr> 
      <tr>
        <th>';       
         $response=$response.'<label>Total number of N.A.Staff:</label>';
$response=$response."<input type='text' name='Tot_N_A_Staff' value='$Tot_N_A_Staff' readonly='readonly'/>";
$response=$response.'<br/>
<br/><label>Designation:</label>';
		$response=$response."<select name='Designation' id='' onChange='Designation(this.value,this.id)'>";
        	$response=$response.'<option value="Select One">Select One</option>';
	  $desi=mysql_query("SELECT DISTINCT(Designation) FROM non_acadamic_staff WHERE  School_Id='$School_Id'");
 while($rowdesi=mysql_fetch_array($desi))
  {
	$response=$response.'<option value="'.$rowdesi['Designation'].'">'.$rowdesi['Designation'].'</option>';
  }
$response=$response.'</select>
         </th>
         <td><div id="Designation">';
	$response=$response."<input type='text' name='Designation' value='$Designation' readonly='readonly'/></div>";
$response=$response.'</td>
         </tr>    
       <tr>
        <th>        
         <label>Number of Required Staffs:</label>
         </th>
         <td>';
         $response=$response."<input type='text' name='No_Of_Required_Staffs' value='$No_Of_Required_Staffs' readonly='readonly'/>";
$response=$response.'</td>
         </tr>         
         <tr>
        <th>        
         <label>Number of Approved Staffs:</label>
         </th>
         <td>';
        $response=$response."<input type='text' name='No_Of_Approved_Staffs' value='$No_Of_Approved_Staffs' readonly='readonly'/>";
$response=$response.'</td>
         </tr>
         <tr>
        <th>        
         <label>Number of Permanent Staffs:</label>
         </th>
         <td>';
         $response=$response."<input type='text' name='No_Of_Permanent_Staffs' value='$No_Of_Permanent_Staffs' readonly='readonly'/>";
$response=$response.'</td>
         </tr>
		 <tr>
        <th>        
         <label>Number of Casual Staffs:</label>
         </th>
         <td>';
         $response=$response."<input type='text' name='No_Of_Casual_Staffs' value='$No_Of_Casual_Staffs' readonly='readonly'/>";
$response=$response.'</td>
         </tr>   
       <tr>
	   <tr>
        <th>        
         <label>Releaf:</label>
         </th>
         <td>';
         $response=$response."<input type='text' name='Releaf' value='$Releaf' readonly='readonly'/>";
$response=$response.'</td>
         </tr>   
       <tr></table>';
}
}
else
{
$response=$hint;
}
echo $response;
?>